package com.example.springbootmybatis.controller;

import com.example.springbootmybatis.mapper.DepartmentMapper;
import com.example.springbootmybatis.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 星空 岳先生
 * @name
 * @date 2022-08-21 17:35
 */

@RestController
public class DepartmentController {
    @Autowired
    DepartmentMapper departmentMapper;

    // 查询全部部门
    @GetMapping("/getDepartments")
    public List<Department> getDepartments() {
        return departmentMapper.getDepartments();
    }

    // 查询部门
    @GetMapping("/getDepartment/{id}")
    public Department getDepartment(@PathVariable("id") Integer id) {
        return departmentMapper.getDepartment(id);
    }

    // 更新部门
    @GetMapping("/updateDepartment")
    public List<Department> updateDepartment() {
        Department department = new Department();
        department.setId(101);
        department.setDepartment_name("应用部‍");
        departmentMapper.updateDepartment(department);
        return departmentMapper.getDepartments();
    }

    // 增加部门
    @GetMapping("/addDepartment")
    public List<Department> addDepartment() {
        Department department = new Department();
        department.setId(106);
        department.setDepartment_name("生活部‍");
        departmentMapper.addDepartment(department);
        return departmentMapper.getDepartments();
    }

    // 删除部门
    @GetMapping("/deleteDepartment/{id}")
    public List<Department> deleteDepartment(@PathVariable("id") Integer id) {
        departmentMapper.deleteDepartment(id);
        return departmentMapper.getDepartments();
    }

}
